<?php
class PXFControllerAdmin extends PXFController
{
	public function __construct()
	{
		parent::__construct(); 
		if(!defined('PXF_LOGIN'))
			self::restrictedAccess();
		$this->tpl->assign('navlinks',PXFConfigAdmin::$adminlinks);
	}

	public function startSmarty()
	{
		$this->tpl = new PXFSiteAdmin_Smarty();
	}

	protected static function restrictedAccess()
	{
		$module = sprintf('admin-%s',PXFInstance::$controller);
		$mod_paccess = PXFModel::getModel('paccess');
		$condition = new PXFCondition('profile_id',PXFInstance::$user->profile_id);
		$condition->add(sprintf(' AND (((module="%s")AND((action="%s")||(action="*"))) || ((module="*")AND(action="*")))',
                                  PXFInstance::$controller,PXFInstance::$action));


		if((PXFInstance::$user->id == PXFConfig::NOBODY_USER) || 
			(count($mod_paccess->findBy(array('condition' => $condition))) == 0))
		{
			$_SESSION['login_success'] = $_SERVER['REQUEST_URI'];
			header(sprintf('Location: %s','index.php?c=login'));
			exit();
		}
	}	
}
?>
